from simplejson import dumps
from django.http import HttpResponse

def json_response(func):
    def newfunc(*a):
        retval = {"response":{}}
        try:
            result = func(*a)
            retval["response"]["status"] = 0
            retval["response"]["data"] = result
        except Exception,e:
            import traceback
            traceback.print_stack()
            retval["response"]["status"] = 1
            retval["response"]["data"] = ':'.join((str(e.__class__), e.message))
        
        return HttpResponse(dumps(retval))
        
    return newfunc
